<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="关键字" prop="keyword">
          <el-input v-model="filterForm.keyword" placeholder="任务ID/任务标题/任务介绍" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="任务时间" prop="publishTime">
          <el-date-picker 
            v-model="filterForm.publishTime"
            value-format="yyyy-MM-dd"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-select v-model="filterForm.status" placeholder="请选择">
              <el-option label="0" value="0">全部</el-option>
              <el-option label="6" value="6">正常</el-option>
              <el-option label="6" value="5">禁用</el-option>
              <el-option label="1" value="1">草稿</el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
              搜索
            </el-button>
            <el-button class="filter-item" style="margin-left: 10px;" type="danger" icon="el-icon-delete" @click="handleRemove">
              删除
            </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      @sort-change="sortChange"
    >
      <el-table-column label="摘要" prop="id" sortable="custom" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="节点" class-name="status-col" min-width="240">
        <template slot-scope="{row}">
            {{ row.node.title }}
        </template>
      </el-table-column>
      <el-table-column label="席位" class-name="status-col" min-width="240">
        <template slot-scope="{row}">
            {{ row.seat }}
        </template>
      </el-table-column>
      <el-table-column label="结束时间" class-name="status-col" width="180">
        <template slot-scope="{row}">
            {{ row.finishTime }}
        </template>
      </el-table-column>
      <el-table-column label="状态" max-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.status.label }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.start" :limit.sync="filterForm.perpage" @pagination="getList" />

  </div>
</template>

<script>
import { getDesignateList  } from '@/api/foundation/designate'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'knowledgeAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      filterForm: {
        start: 1,
        perpage: 10,
        title: undefined,
        sort: '+id'
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      getDesignateList(this.filterForm).then(response => {
        this.list = response.data.list
        this.total = response.data.total

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleShow:function(item){
      this.$router.push({ path: 'track-detail', query: { 'designateID': item.ID }})
    },
    handleFilter() {
      this.filterForm.start = 1
      this.getList()
    }
  }
}
</script>
